package com.holly.unit.bpmn.activiti.ext;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.holly.unit.bpmn.activiti.entity.ActFrom;
import com.holly.unit.bpmn.activiti.mapper.ActFromMapper;
import com.holly.unit.bpmn.activiti.pojo.ActFromRequest;
import com.holly.unit.bpmn.activiti.pojo.dto.ActFromDTO;
import com.holly.unit.db.api.factory.PageFactory;
import com.holly.unit.db.api.factory.PageResultFactory;
import com.holly.unit.db.api.pojo.page.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ActFromService extends ServiceImpl<ActFromMapper, ActFrom> {

    @Autowired
    private ActFromMapper fromMapper;

    public PageResult<ActFromDTO> getFromPage(ActFromRequest actFromRequest) {
        Page<ActFromDTO> fromPage = fromMapper.getFromPage(PageFactory.defaultPage(), actFromRequest);
        return PageResultFactory.createPageResult(fromPage);
    }

    public void editActFrom(ActFromRequest actFromRequest) {
        ActFrom actFrom = new ActFrom();
        BeanUtil.copyProperties(actFromRequest, actFrom);
        this.updateById(actFrom);

    }

    public void addActFrom(ActFromRequest actFromRequest) {
        ActFrom actFrom = new ActFrom();
        BeanUtil.copyProperties(actFromRequest, actFrom);
        this.save(actFrom);
    }

    public ActFromDTO getActFormById(String id) {
        return fromMapper.getActFormById( id);
    }
}
